package cn.wyz.system.service.impl;

import cn.wyz.system.domain.Role;
import cn.wyz.system.mapper.RoleMapper;
import cn.wyz.system.service.IRoleService;
import cn.wyz.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * role:角色表
 * 当前mapper会影响角色的权限分配,这里就是对角色的权限进行变更
 *
 * @author WuyuZ
 * @since 2022-06-22
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Transactional
    public void insert(Role role) {
        roleMapper.insert(role);
    }

    public void inintRelationtable(Role role){
        //前端要求必须传递最新的全量数据， 我们直接做全量覆盖
        //1.删除历史数据
        roleMapper.deleteRoleMenuByRoleId(role.getId());
        roleMapper.deleteRolePermissionByRoleId(role.getId());
        //2.直接保存角色权限表数据,前端传回来所有的权限我们全盘接受,全部拿下
        roleMapper.insertRoleMenu(role);
        //3.保存角色菜单表数据
        roleMapper.insertRolePermission(role);
    }

    @Override
    @Transactional
    public void update(Role role) {
        super.update(role);
    }

    @Override
    @Transactional
    public void deleteById(Long id) {
        super.deleteById(id);
    }
}
